home *** CD-ROM | disk | FTP | other *** search
- /* C14CalculatorData.c -- application-specific data management */
-
- /* look at this, check for nil? */
-
- /* This module contains data structures to access the data in your */
- /* document's file(s). The purpose is to isolate the details of the */
- /* data representation into this module and to provide accessor */
- /* functions for reading/writing logical pieces of the data. */
- /* For your application, you will probably rewrite most of this. */
- /* This module will not be regenerated by AppMaker unless you delete it. */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Events.h>
- /*#include <Lists.h>*/
- #include <Menus.h>
- #include <TextEdit.h>
- #include "Globals.h"
- #include "Miscellany.h"
-
- #include "PredatorPreyData.h"
- #ifndef __C14__
- #include "PredatorPrey.h"
- #endif
- #include "calc_dipshit.h"
- #include "Cursors.h"
- #include "ParseDataString.h"
-
-
- /* Define additional "private" data structures. */
-
- #define yesNoCancelDLOG 132
- #define errorDLOG 256
- #define MaxPoints 2500
-
- SFReply sfInfo;
- extern TEHandle theTEHndl;
- Handle theTextHndl; /*extern*/
- extern CharsHandle theCharsHndl;
- extern CharsHandle theChars2Hndl;
- extern short gWindowState;
- extern short gMatWin;
- extern long gState;
- extern double aaa[MaxPoints][3];
-
- pascal void HiliteDefaultButton(DialogPtr theDPtr, short whichItem);
- char tempString[256];
-
- struct cNode;
- struct dData;
- struct dNode;
-
-
- struct Root
- {
- struct cNode *cNext;
- };
-
- struct Root *theRootPtr, *rCurrentPtr;
-
- struct cNode
- {
- struct cNode *cNext;
- struct dNode *dNext;
- short cCount;
- double_t runConst;
-
- };
-
- struct cNode *cCurrentPtr, *cTempPtr;
-
- struct dNode
- {
- struct dNode *dNext;
- short dCount;
- short dataCount;
- double_t runData;
- //struct dData *daNext;
- };
-
- struct dNode *dCurrentPtr, *dTempPtr;
-
-
-
- typedef struct {
- short data;
- } MoreStuff;
-
- void CenterSWindow (WindowPtr wPtr);
- extern void ErrorShow (short which);
- extern void ResultDeParse ( double_t resultIn,
- short *fxLen,
- short *flLen
- );
-
-
- void C14Data_seg() {} /* for reference in "UnloadSeg()" calls */
-
- /*----------*/
- void AddStuff (YourStuff *stuff)
- {
- #pragma unused (stuff)
-
- } /* AddStuff */
-
- /*----------*/
- Boolean GetStuff (void)
- {
- return (false);
- } /* GetStuff */
-
-
- /*----------*/
- void DeleteStuff (void)
- {
- } /* DeleteStuff */
-
- void InitMapData (Str255 *fName, short refNum, short qRefNum)
- /* ^ ^ ^ */
- /* | | | */
- /* | | *---- file reference number */
- /* | *-- working directory of current system folder */
- /* *---- data filename */
- {
- short i,j;
- StringHandle dataFileName;
-
- map.mem2name[0] = 6;
- map.mem2name[1] = 'i';
- map.mem2name[2] = 'k';
- map.mem2name[3] = 'a';
- map.mem2name[4] = 'b';
- map.mem2name[5] = 'a';
- map.mem2name[6] = 's';
- map.mem3name[0] = 28;
- map.mem4name[0] = 28; /*PtrToHand(&(*fName),dataFileName,sizeof(fName));*/
- dataFileName = NewString( *fName );
- BlockMove(*dataFileName,*cur->qFilename,GetHandleSize((Handle) dataFileName));
- cur->qFileNum = qRefNum;
- DumbShit(2);
- }
-
- /*----------*/
- void InitAppData (void)
- {
- } /* InitAppData */
-
- /*----------*/
- void DisposeAppData (void)
- {
- } /* DisposeAppData */
-
- /*----------*/
- Boolean OpenAppFile (short vRefNum,
- Str255 fName,
- short *fRefNum)
- {
- Boolean okay;
-
- okay = CheckOS (FSOpen (fName, vRefNum, fRefNum));
- return (okay);
- } /* OpenAppFile */
-
- /*----------*/
- void CloseAppFile (short fRefNum)
- {
- Boolean okay;
-
- if (fRefNum != 0) { /* could be 0 if closing new document */
- okay = CheckOS (FSClose (fRefNum));
- }
- } /* CloseAppFile */
-
- /*----------*/
- void ReadAppFile (short fRefNum)
- {
- /*#pragma unused (fRefNum)*/
- OSErr error;
- long fcount;
-
- fcount = sizeof(frog);
- error = SetFPos(fRefNum,1,0);
- error = FSRead(fRefNum,&fcount,&frog);
-
- InitAppData ();
- } /* ReadAppFile */
-
-
- void ErrorAlert(char *p0) /* is pZERO */
- {
- GrafPtr oldPort;
- DialogPtr theDPtr,tempDPtr;
- short itemHit, type;
- Handle theItem;
- Rect theRect;
- EventRecord theEvent;
- /*char p1;*/
-
- /*Str255 pZero;*/
- short i;
-
- GetPort(&oldPort);
-
- InitCursor();
-
- if (!(theDPtr = GetNewDialog(errorDLOG, NULL,(WindowPtr) -1L)))
- {
- SysBeep(1);
- ExitToShell();
- }
-
- SetPort(theDPtr);
-
- CenterSWindow(theDPtr);
- ShowWindow(theDPtr);
-
- ((DialogPeek) theDPtr)->aDefItem = 1;
-
- GetDItem(theDPtr, 3, &type, &theItem, &theRect);
- SetDItem(theDPtr, 3, type, (Handle)HiliteDefaultButton, &theRect);
-
- GetDItem(theDPtr, 2, &type, &theItem, &theRect);
-
- /**strcpy(*p1,*p0);*/
- CtoPstr(p0);
- SetIText(theItem, (ConstStr255Param)p0);
- /*PtoCstr(p0);*/
-
- while (!GetNextEvent(updateMask,&theEvent));
-
- if (theEvent.message == (long) theDPtr)
- DialogSelect(&theEvent,&tempDPtr,&itemHit);
-
- SysBeep(1);
-
- do
- {
- itemHit = 0;
-
- while (!GetNextEvent(everyEvent,&theEvent));
-
- if (theEvent.what==keyDown || theEvent.what==autoKey)
- {
- if ((theEvent.message & charCodeMask)=='\r' || (theEvent.message & charCodeMask)==0x03)
- itemHit = ((DialogPeek) theDPtr)->aDefItem;
- else
- SysBeep(1);
- }
-
- else
- {
- tempDPtr = (DialogPtr) 0L;
-
- if (!IsDialogEvent(&theEvent) || !DialogSelect(&theEvent,&tempDPtr,&itemHit) || tempDPtr!=theDPtr)
- itemHit = 0;
- }
-
- } while (itemHit!=1);
-
- DisposDialog(theDPtr);
- SetPort(oldPort);
- }
-
-
-
- /*----------*/
- void CenterSWindow(WindowPtr wPtr)
- {
- int screenWidth,screenHeight,windowWidth,windowHeight,left,top;
-
- if (wPtr == 0L)
- return;
-
- screenWidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
- screenHeight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - 20;
- windowWidth = wPtr->portRect.right - wPtr->portRect.left;
- windowHeight = wPtr->portRect.bottom - wPtr->portRect.top;
-
- left = qd.screenBits.bounds.left + (screenWidth - windowWidth)/2;
- top = qd.screenBits.bounds.top + 20 + (screenHeight - windowHeight)/2;
-
- if (left < 0)
- left = 0;
-
- if (top < 20)
- top = 20;
-
- MoveWindow(wPtr,left,top,FALSE);
- }
-
-
- /*----------*/
- void WriteAppFile (short type, short fRefNum)
- {
- /*#pragma unused (fRefNum)*/
- OSErr error;
- long count,fcount,mcount;
-
- count = sizeof(map);
- fcount = sizeof(frog);
- //mcount = sizeof(aaa[][3]); /* frog for now */
-
- error = SetFPos(fRefNum,1,0);
-
- switch(type)
- {
- case 0:
- error = FSWrite(fRefNum,&count,&map);
- break;
- case 1:
- error = FSWrite(fRefNum,&fcount,&frog);
- break;
- // case 2:
- // error = FSWrite(fRefNum,&mcount,&log);
- // break;
- }
- error = FlushVol(NIL,cur->volNum);
- } /* WriteAppFile */
-
- /* AMTstShrData */
-
- pascal void HiliteDefaultButton(DialogPtr theDPtr,short whichItem)
- {
- short type;
- Handle theItem;
- Rect theRect;
-
- GetDItem(theDPtr, ((DialogPeek) theDPtr)->aDefItem, &type, &theItem, &theRect);
- PenNormal();
- PenSize(3,3);
- InsetRect(&theRect,-4,-4);
- FrameRoundRect(&theRect,16,16);
- PenSize(1,1);
- }
-
-
- short YesNoCancel(char *thePrompt,short theDefault)
- {
- DialogPtr theDPtr,tempDPtr;
- short itemHit, type;
- Handle theItem;
- Rect tempRect;
- GrafPtr oldPort;
- char tempString[256];
- EventRecord theEvent;
-
- GetPort(&oldPort);
-
- InitCursor();
-
- theDPtr = GetNewDialog(yesNoCancelDLOG, 0L,(WindowPtr) -1L);
-
- CenterSWindow(theDPtr);
- ShowWindow(theDPtr);
-
- SetPort(theDPtr);
-
- ((DialogPeek) theDPtr)->aDefItem = theDefault;
-
- GetDItem(theDPtr, 4, &type, &theItem, &tempRect);
- SetDItem(theDPtr, 4, type, (Handle)HiliteDefaultButton, &tempRect);
-
- /*strcpy(tempString,thePrompt);*/
- CtoPstr(tempString);
- GetDItem(theDPtr, 5, &type, &theItem, &tempRect);
- SetIText(theItem, (ConstStr255Param)tempString);
-
- if (GetNextEvent(updateMask,&theEvent) && theEvent.message == (long) theDPtr)
- DialogSelect(&theEvent,&tempDPtr,&itemHit);
-
- SysBeep(1);
-
- do
- {
- ModalDialog(0L,&itemHit);
-
- } while (!(itemHit>=1 && itemHit<=3));
-
- DisposDialog(theDPtr);
- SetPort(oldPort);
-
- return(itemHit);
- }
-
-